package code.starivan.niuke.jianoffer;

import java.util.ArrayList;
import java.util.Stack;

/**
 * Created by Ivan on 2015/8/23.
 */
public class PrintList {

    public class ListNode {
        int val;
        ListNode next = null;

        ListNode(int val) {
            this.val = val;
        }
    }

    public ArrayList<Integer> printListFromTailToHead(ListNode listNode) {
        if(listNode==null)
            return null;

        ArrayList<Integer> data=new ArrayList<>();

        Stack<Integer> stack=new Stack<Integer>();

        while (listNode!=null){
            stack.push(listNode.val);
            listNode=listNode.next;
        }

        while (!stack.empty()){
            data.add(stack.pop());
        }

        return  data;
    }

}
